// packageH/toker/memberTokerCard/memberTokerCard.js
var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    page: 1, //分页数，当前页数
    isLoadMore: true, //判断是否要加载更多的标志
    total_page: 0, //总页数

    listData: [],
    plugin_name:'拓客卡'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getData();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  tokerSetMeal(evt) {
    let id = evt.currentTarget.dataset.id;
    wx.navigateTo({
      url: "/packageH/toker/tokerSetMeal/tokerSetMeal?id=" + id,
    });
  },

  gotoCode(evt) {
    let id = evt.currentTarget.dataset.id;
    wx.navigateTo({
      url: "/packageH/toker/tokerCode/tokerCode?id=" + id+'&name='+this.data.plugin_name,
    });
  },

  getData() {
    let urlStr = app.getNetAddresss("plugin.customer-development.Frontend.controllers.card.index");
    app._postNetWork({
      url: urlStr,
      success: (resdata) => {
        var res = resdata.data;
        if (res.result != 1) return app.tips(res.msg);
        this.data.total_page = res.data.last_page;
        if (!this.data.total_page) {
          this.data.total_page = 0;
        }
        let _team = res.data.data;
        this.setData({
          listData: _team,
          plugin_name:res.data.plugin_name
        });
        wx.setNavigationBarTitle({
          title: res.data.plugin_name?res.data.plugin_name:'拓客卡',
        });
      },
    });
  },

  //加载更多数据
  _getMoreData() {
    this.data.isLoadMore = false; // 防止多次请求分页数据
    if (this.data.page >= this.data.total_page) {
      // that.loading = true;
      return;
    } else {
      this.data.page += 1;
      let urlStr = app.getNetAddresss("plugin.customer-development.Frontend.controllers.card.index");
      app._postNetWork({
        url: urlStr,
        data: {
          page: this.data.page,
        },
        success: (resdata) => {
          let res = resdata.data;
          this.data.isLoadMore = true;
          if (res.result === 1) {
            let _team = res.data.data;
            let listData = this.data.listData.concat(_team);
            this.setData({ listData });
          } else {
            this.data.page = this.data.page - 1;
            this.data.isLoadMore = false;
          }
        },
      });
    }
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.isLoadMore) {
      this._getMoreData();
    } else {
      console.log("没有更多数据");
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (evt) {
    console.log(evt);
    let id = evt.target.dataset.id;
    return {
      path: "/packageA/detail_v2/detail_v2?id=" + id,
    };
  },
});
